<template>
	<view v-if="display" class="tui-cards-container">
		<view class="tui-cards-box">
			<view class="tui-cards-title">

				<view v-if="orderinf.orderNum">你要发送该订单吗</view>
				<view v-else>你要发送该测评吗</view>
				<view style="color: #006EFF; font-family: PingFangSC-Regular;" class="tui-cards-close" @tap="handleClose">关闭</view>
			</view>
<!--			<view class="tui-search-bar">-->
<!--				<image class="tui-searchcion" src="/static/static/assets/serach-icon.svg"></image>-->
<!--				<input class="tui-search-bar-input" :value="words" placeholder="搜索" @input="wordsInput" />-->
<!--			</view>-->
			<scroll-view class="tui-order-list" scroll-y="true" enable-flex="true">

        <view class="order-title" v-if="orderinf.orderNum">
						<view class="order-number">订单编号: {{orderinf.orderNum }}</view>
						<view class="order-time">{{orderinf.time }}</view>
					</view>
					<view class="order-info">
						<image class="order-image" :src="orderinf.imageUrl"></image>
						<view class="order-content">
							<view class="order-content-title">{{orderinf.title }}</view>
							<view class="order-content-description">{{orderinf.description }}</view>
							<view style="display: flex; flex-wrap: no-wrap; justify-content: space-between;">
								<view class="order-content-price">{{orderinf.price }}</view>
								<view class="btn-send-order" :data-order="orderinf" @tap.stop="sendMessage">
                  <text class="btn-send-text" v-if="orderinf.orderNum">发送此订单</text>
                  <text class="btn-send-text" v-else>发送此测评</text>

                </view>
							</view>
						</view>
					</view>

			</scroll-view>
		</view>
	</view>
</template>

<script>
const orderList = [
	{
		orderNum: 1,
		time: '2021-7-20 20:45',
		title: '[天博检验]新冠核酸检测/预约',
		description: '专业医学检测，电子报告',
		imageUrl: 'https://sdk-web-1252463788.cos.ap-hongkong.myqcloud.com/component/TUIKit/assets/miles.jpeg',
		price: '80元'
	}
	// {
	// 	orderNum: 2,
	// 	time: '2021-7-20 22:45',
	// 	title: '[路边]新冠核酸检测/预约',
	// 	description: '专业医学检测，电子报告',
	// 	imageUrl: 'https://sdk-web-1252463788.cos.ap-hongkong.myqcloud.com/component/TUIKit/assets/miles.jpeg',
	// 	price: '7000元'
	// }
];

export default {
	data() {
		return {
			words: '',
			orderMatch: orderList
		};
	},

	components: {},
	props: {
		display: {
			type: Boolean,
			default: false
		},
		conversation: {
			type: Object,
			default: () => {}
		},
    orderinf: {
			type: Object,
			default: () => {}
		}
	},
	watch: {
		display: {
			handler: function(newVal) {
				// this.setData({
				//   display: newVal
				// });
			},
			immediate: true
		},
		conversation: {
			handler: function(newVal) {
				this.setData({
					conversation: newVal
				});
			},
			immediate: true,
			deep: true
		}
	},
	methods: {
		handleClose() {
			this.$emit('close', {
				detail: {
					key: '1'
				}
			});
		},

		wordsInput(e) {
			(this.orderMatch = []),
				orderList.forEach(item => {
					if (item.title.indexOf(e.detail.value) > -1 || item.orderNum === ~~e.detail.value) {
						this.orderMatch.push(item);
					}
				});
			this.setData({
				words: e.detail.value,
				orderMatch: this.orderMatch
			});
		},

		sendMessage(e) {
			const { order } = e.currentTarget.dataset;
			//判断订单状态更改数据库os_accept表信息
      if(order.state ==1){
       let obj = {};
        obj.to_user_id = uni.getStorageSync("userId");
        obj.user_id = order.toOtheruser_id
        obj.shop_evaluation_id = order.shop_evaluation_id
        obj.is_accept = 0
        obj.bao = 0
        this.$u.api.shopEvaluationAccept(obj).then(res => {
          this.$emit('showAccept',1);
        })
      }
      //报名发过来的报完名后刷新状态  暂时没有,接口改状态
      // if(order.bao==1){
      //   let obj = {};
      //   // obj.to_user_id = uni.getStorageSync("userId");
      //   // obj.user_id = order.toOtheruser_id
      //   // obj.shop_evaluation_id = order.shop_evaluation_id
      //   // obj.is_accept = 1
      //   // obj.bao = order.bao
      //   // this.$u.api.shopEvaluationAccept(obj).then(res => {
      //     this.$emit('showAccept',1);
      //   // })
      // // }
			this.$emit('sendCustomMessage', {
				detail: {
					payload: {
						// data 字段作为表示，可以自定义
						data: 'order',
						description: order.description,
						// 获取骰子点数
						extension: JSON.stringify({
              orderNum: order.orderNum,
							title: order.title,
							imageUrl: order.imageUrl,
							price: order.price,
              confirm:order.confirm,
              cancel:order.cancel,
              types:order.types,
              order_id:order.order_id,
              money:order.money,
              state:order.state,
              toOtheruser_id:order.toOtheruser_id,
              shop_evaluation_id:order.shop_evaluation_id,
              bao:order.bao
						})
					}
				}
			});
		}
	}
};
</script>
<style>
@import './index.css';
</style>
